//Copyright (C) 2012 Chirila Alexandru
//This file is part of Mirror FTP
//
//Mirror FTP is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//Mirror FTP is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with Mirror FTP.  If not, see <http://www.gnu.org/licenses/>.

#ifndef CONN_CMD_H_
#define CONN_CMD_H_

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>

//#include <iostream>
#include <sstream>
//#include <string>

#include <unistd.h>
#include <fcntl.h>

#include <netdb.h>
#include <sys/socket.h>
#include <sys/un.h>

#include <netinet/in.h>
#include <arpa/inet.h>

#include "model.h"

using namespace std;

/** Class that manages the control connection of the ftp client
 * 	by sending commands and receiving replies from server
 */
class conn_cmd{
private:

	string address;					///<address of current machine (resolved after establishing connection)
	string last_resp;				///<last reply from server

	int sockfd;						///<socket used to communicate with server
	int portno;						///<port number

	struct sockaddr_in serv_addr;
public:
	conn_cmd();
	~conn_cmd();
public:
	string get_last_resp(){return last_resp;};
	string getAddr(){return address;}
	int get_reply_int(string m);

	int login(string u,string p);
	int establish(struct hostent server,int port);
	int send_cmd(string c,string p);
	int read_more();

	int send_port(int);

	int closeC();

	int connected();
private:
	int fd_set_blocking(int fd, int blocking);
};



#endif /* CONN_CMD_H_ */
